USE [BukstorBD]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Reservas_Clientes]') AND parent_object_id = OBJECT_ID(N'[dbo].[Reservas]'))
ALTER TABLE [dbo].[Reservas] DROP CONSTRAINT [FK_Reservas_Clientes]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Reservas_Libros]') AND parent_object_id = OBJECT_ID(N'[dbo].[Reservas]'))
ALTER TABLE [dbo].[Reservas] DROP CONSTRAINT [FK_Reservas_Libros]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_Reservas_fecha]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[Reservas] DROP CONSTRAINT [DF_Reservas_fecha]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_Reservas_ingresoInventario]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[Reservas] DROP CONSTRAINT [DF_Reservas_ingresoInventario]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_Reservas_cantidad]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[Reservas] DROP CONSTRAINT [DF_Reservas_cantidad]
END

GO

USE [BukstorBD]
GO

/****** Object:  Table [dbo].[Reservas]    Script Date: 11/25/2012 20:18:02 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Reservas]') AND type in (N'U'))
DROP TABLE [dbo].[Reservas]
GO

USE [BukstorBD]
GO

/****** Object:  Table [dbo].[Reservas]    Script Date: 11/25/2012 20:18:02 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Reservas](
	[idReserva] [int] IDENTITY(1,1) NOT NULL,
	[idCliente] [int] NOT NULL,
	[idLibro] [int] NOT NULL,
	[fecha] [date] NOT NULL,
	[ingresoInventario] [bit] NOT NULL,
	[fechaIngresoInventario] [date] NULL,
	[cantidad] [tinyint] NOT NULL,
 CONSTRAINT [PK_Reservas] PRIMARY KEY CLUSTERED 
(
	[idReserva] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Reservas]  WITH CHECK ADD  CONSTRAINT [FK_Reservas_Clientes] FOREIGN KEY([idCliente])
REFERENCES [dbo].[Clientes] ([idCliente])
GO

ALTER TABLE [dbo].[Reservas] CHECK CONSTRAINT [FK_Reservas_Clientes]
GO

ALTER TABLE [dbo].[Reservas]  WITH CHECK ADD  CONSTRAINT [FK_Reservas_Libros] FOREIGN KEY([idLibro])
REFERENCES [dbo].[Libros] ([idLibro])
GO

ALTER TABLE [dbo].[Reservas] CHECK CONSTRAINT [FK_Reservas_Libros]
GO

ALTER TABLE [dbo].[Reservas] ADD  CONSTRAINT [DF_Reservas_fecha]  DEFAULT (getdate()) FOR [fecha]
GO

ALTER TABLE [dbo].[Reservas] ADD  CONSTRAINT [DF_Reservas_ingresoInventario]  DEFAULT ((0)) FOR [ingresoInventario]
GO

ALTER TABLE [dbo].[Reservas] ADD  CONSTRAINT [DF_Reservas_cantidad]  DEFAULT ((1)) FOR [cantidad]
GO

